package info.openlvb.openface.client.handler;

import info.openlvb.openface.client.base.person.ListGroupPanel;
import info.openlvb.openface.client.base.person.MemberInGroupWindow;
import info.openlvb.openface.client.service.LdapService;
import info.openlvb.openface.client.service.LdapServiceAsync;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.MessageBox;
import com.gwtext.client.widgets.event.ButtonListenerAdapter;

public class ModifyGroupListener extends ButtonListenerAdapter {

	private MemberInGroupWindow memberInGroupWindow;
	private String groupname;
	private ListGroupPanel listGroupPanel;
	private final LdapServiceAsync ldapService = GWT.create(LdapService.class);
	
	public ModifyGroupListener(MemberInGroupWindow memberInGroupWindow, ListGroupPanel listGroupPanel, String groupname){
		this.memberInGroupWindow = memberInGroupWindow;
		this.listGroupPanel=listGroupPanel;
		this.groupname = groupname;
	}
	public void onClick(Button button, EventObject e) {
		ldapService.modifyGroup(groupname, memberInGroupWindow.getTxt_nom().getText(), memberInGroupWindow.getTxt_desc().getText(), new AsyncCallback<Void>() {
			public void onFailure(Throwable caught) {
				MessageBox.alert("probleme ...", "probleme acces au backend");
			}
			public void onSuccess(Void result) {
				listGroupPanel.refresh();
				memberInGroupWindow.hide();
			}
		});

	}

}
